/*******************************************************************************
 * Copyright (c) 2006 CEA List.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     CEA List - initial API and implementation
 *******************************************************************************/
package com.cea.papyrus.core.ui.dialogs;

import org.eclipse.jface.dialogs.IInputValidator;
import org.eclipse.uml2.uml.Port;

import com.cea.papyrus.classdiagram.parsers.modelgenerator.PortGenerator;

/**
 * Validator for Port Labels.
 * 
 * @see org.eclipse.jface.dialogs.InputDialog
 * @author Remi SCHNEKENBURGER
 */
public class PortLabelValidator implements IInputValidator {

	/**
	 * 
	 */
	private Port port;
	
	/**
	 * 
	 * 
	 * @return the port
	 */
	public Port getPort() {
		return port;
	}

	/**
	 * 
	 * 
	 * @param port the port to set
	 */
	public void setPort(Port port) {
		this.port = port;
	}
	
	/**
	 * 
	 * 
	 * @param port 
	 */
	public PortLabelValidator(Port port) {
		super();
		setPort(port);
	}
	
	/* (non-Javadoc)
	 * @see org.eclipse.jface.dialogs.IInputValidator#isValid(java.lang.String)
	 */
	/**
	 * 
	 * 
	 * @param newText 
	 * 
	 * @return 
	 */
	public String isValid(String newText) {
		PortGenerator generator = new PortGenerator(port);
		return generator.parseAndValidatePort(newText);
	}

}
